/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.cicp.message;

import javax.jms.JMSException;

import com.sinodata.bsm.common.message.AsyncSession;
import com.sinodata.bsm.common.message.ServiceMessage;
import com.sinodata.bsm.common.message.SyncSession;
import com.sinodata.bsm.common.vo.Event;
import com.sinodata.bsm.common.vo.FaultTrapMsg;
import com.sinodata.bsm.common.vo.ResPropertyValue;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author tangli
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-7 下午4:57:41          tangli_ITSM        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public final class Messenger {
    private static Messenger instance = new Messenger();

    private static final String eventQueueName = "ASY_EVT";
    private static final String evtQueueName = "TRAP";

    private String syncQueueName = null;
    private SyncSession syncSession = null;
    private AsyncSession asynSession = null;

    private AsyncSession trapAsyncSession = null;
    private AsyncSession eventAsyncSession = null;

    /**
     * 
     */
    private Messenger() {
    }

    public static Messenger getInstance() {
        return instance;
    }

    public synchronized void init(Long probeId) {
        this.syncQueueName = "SYNC_PTC";
        this.syncSession = new SyncSession(syncQueueName);
        this.asynSession = new AsyncSession("PROP_" + probeId);
        this.trapAsyncSession = new AsyncSession(evtQueueName); //异步发送事件
        this.eventAsyncSession = new AsyncSession(eventQueueName);//异步发送事件到事件队列
    }

    public Object sendServiceMessage(ServiceMessage msg) throws JMSException {
        return syncSession.send(msg);
    }

    public void sendPropertyValue(ResPropertyValue value) throws JMSException {
        this.asynSession.send(value);
    }

    /**
     * 发送TRAP消息
     * @param trap
     * @throws JMSException
     */
    public void sendTrap(FaultTrapMsg trap) throws JMSException {
        this.trapAsyncSession.send(trap);
    }

    /**
     * 直接发送事件到事件队列
     * @param event
     * @throws JMSException
     */
    public void sendEvent(Event event) throws JMSException {
        this.eventAsyncSession.send(event);
    }
}
